package it.stasbranger.myproject.web.rest;

import it.stasbranger.myproject.dao.RequestsDAO;
import it.stasbranger.myproject.dao.SuppliersDAO;
import it.stasbranger.myproject.dao.SuppliersHasRequestsDAO;

import it.stasbranger.myproject.domain.Requests;
import it.stasbranger.myproject.domain.Suppliers;
import it.stasbranger.myproject.domain.SuppliersHasRequests;

import it.stasbranger.myproject.service.SuppliersHasRequestsService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Spring Rest controller that handles CRUD requests for SuppliersHasRequests entities
 * 
 */

@Controller("SuppliersHasRequestsRestController")
public class SuppliersHasRequestsRestController {

	/**
	 * DAO injected by Spring that manages Requests entities
	 * 
	 */
	@Autowired
	private RequestsDAO requestsDAO;

	/**
	 * DAO injected by Spring that manages Suppliers entities
	 * 
	 */
	@Autowired
	private SuppliersDAO suppliersDAO;

	/**
	 * DAO injected by Spring that manages SuppliersHasRequests entities
	 * 
	 */
	@Autowired
	private SuppliersHasRequestsDAO suppliersHasRequestsDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for SuppliersHasRequests entities
	 * 
	 */
	@Autowired
	private SuppliersHasRequestsService suppliersHasRequestsService;

	/**
	 * Delete an existing Suppliers entity
	 * 
	 */
	@RequestMapping(value = "/SuppliersHasRequests/{suppliershasrequests_suppliersIdsuppliers}/{suppliershasrequests_requestsIdrequests}/suppliers/{suppliers_idsuppliers}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteSuppliersHasRequestsSuppliers(@PathVariable Integer suppliershasrequests_suppliersIdsuppliers, @PathVariable Integer suppliershasrequests_requestsIdrequests, @PathVariable Integer related_suppliers_idsuppliers) {
		suppliersHasRequestsService.deleteSuppliersHasRequestsSuppliers(suppliershasrequests_suppliersIdsuppliers, suppliershasrequests_requestsIdrequests, related_suppliers_idsuppliers);
	}

	/**
	 * Save an existing Requests entity
	 * 
	 */
	@RequestMapping(value = "/SuppliersHasRequests/{suppliershasrequests_suppliersIdsuppliers}/{suppliershasrequests_requestsIdrequests}/requests", method = RequestMethod.PUT)
	@ResponseBody
	public Requests saveSuppliersHasRequestsRequests(@PathVariable Integer suppliershasrequests_suppliersIdsuppliers, @PathVariable Integer suppliershasrequests_requestsIdrequests, @RequestBody Requests requests) {
		suppliersHasRequestsService.saveSuppliersHasRequestsRequests(suppliershasrequests_suppliersIdsuppliers, suppliershasrequests_requestsIdrequests, requests);
		return requestsDAO.findRequestsByPrimaryKey(requests.getIdrequests());
	}

	/**
	 * Show all SuppliersHasRequests entities
	 * 
	 */
	@RequestMapping(value = "/SuppliersHasRequests", method = RequestMethod.GET)
	@ResponseBody
	public List<SuppliersHasRequests> listSuppliersHasRequestss() {
		return new java.util.ArrayList<SuppliersHasRequests>(suppliersHasRequestsService.loadSuppliersHasRequestss());
	}

	/**
	 * Delete an existing SuppliersHasRequests entity
	 * 
	 */
	@RequestMapping(value = "/SuppliersHasRequests/{suppliershasrequests_suppliersIdsuppliers}/{suppliershasrequests_requestsIdrequests}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteSuppliersHasRequests(@PathVariable Integer suppliershasrequests_suppliersIdsuppliers, @PathVariable Integer suppliershasrequests_requestsIdrequests) {
		SuppliersHasRequests suppliershasrequests = suppliersHasRequestsDAO.findSuppliersHasRequestsByPrimaryKey(suppliershasrequests_suppliersIdsuppliers, suppliershasrequests_requestsIdrequests);
		suppliersHasRequestsService.deleteSuppliersHasRequests(suppliershasrequests);
	}

	/**
	 * View an existing Suppliers entity
	 * 
	 */
	@RequestMapping(value = "/SuppliersHasRequests/{suppliershasrequests_suppliersIdsuppliers}/{suppliershasrequests_requestsIdrequests}/suppliers/{suppliers_idsuppliers}", method = RequestMethod.GET)
	@ResponseBody
	public Suppliers loadSuppliersHasRequestsSuppliers(@PathVariable Integer suppliershasrequests_suppliersIdsuppliers, @PathVariable Integer suppliershasrequests_requestsIdrequests, @PathVariable Integer related_suppliers_idsuppliers) {
		Suppliers suppliers = suppliersDAO.findSuppliersByPrimaryKey(related_suppliers_idsuppliers, -1, -1);

		return suppliers;
	}

	/**
	 * Create a new Requests entity
	 * 
	 */
	@RequestMapping(value = "/SuppliersHasRequests/{suppliershasrequests_suppliersIdsuppliers}/{suppliershasrequests_requestsIdrequests}/requests", method = RequestMethod.POST)
	@ResponseBody
	public Requests newSuppliersHasRequestsRequests(@PathVariable Integer suppliershasrequests_suppliersIdsuppliers, @PathVariable Integer suppliershasrequests_requestsIdrequests, @RequestBody Requests requests) {
		suppliersHasRequestsService.saveSuppliersHasRequestsRequests(suppliershasrequests_suppliersIdsuppliers, suppliershasrequests_requestsIdrequests, requests);
		return requestsDAO.findRequestsByPrimaryKey(requests.getIdrequests());
	}

	/**
	 * Save an existing SuppliersHasRequests entity
	 * 
	 */
	@RequestMapping(value = "/SuppliersHasRequests", method = RequestMethod.PUT)
	@ResponseBody
	public SuppliersHasRequests saveSuppliersHasRequests(@RequestBody SuppliersHasRequests suppliershasrequests) {
		suppliersHasRequestsService.saveSuppliersHasRequests(suppliershasrequests);
		return suppliersHasRequestsDAO.findSuppliersHasRequestsByPrimaryKey(suppliershasrequests.getSuppliersIdsuppliers(), suppliershasrequests.getRequestsIdrequests());
	}

	/**
	 * Get Requests entity by SuppliersHasRequests
	 * 
	 */
	@RequestMapping(value = "/SuppliersHasRequests/{suppliershasrequests_suppliersIdsuppliers}/{suppliershasrequests_requestsIdrequests}/requests", method = RequestMethod.GET)
	@ResponseBody
	public Requests getSuppliersHasRequestsRequests(@PathVariable Integer suppliershasrequests_suppliersIdsuppliers, @PathVariable Integer suppliershasrequests_requestsIdrequests) {
		return suppliersHasRequestsDAO.findSuppliersHasRequestsByPrimaryKey(suppliershasrequests_suppliersIdsuppliers, suppliershasrequests_requestsIdrequests).getRequests();
	}

	/**
	 * Create a new SuppliersHasRequests entity
	 * 
	 */
	@RequestMapping(value = "/SuppliersHasRequests", method = RequestMethod.POST)
	@ResponseBody
	public SuppliersHasRequests newSuppliersHasRequests(@RequestBody SuppliersHasRequests suppliershasrequests) {
		suppliersHasRequestsService.saveSuppliersHasRequests(suppliershasrequests);
		return suppliersHasRequestsDAO.findSuppliersHasRequestsByPrimaryKey(suppliershasrequests.getSuppliersIdsuppliers(), suppliershasrequests.getRequestsIdrequests());
	}

	/**
	 * Create a new Suppliers entity
	 * 
	 */
	@RequestMapping(value = "/SuppliersHasRequests/{suppliershasrequests_suppliersIdsuppliers}/{suppliershasrequests_requestsIdrequests}/suppliers", method = RequestMethod.POST)
	@ResponseBody
	public Suppliers newSuppliersHasRequestsSuppliers(@PathVariable Integer suppliershasrequests_suppliersIdsuppliers, @PathVariable Integer suppliershasrequests_requestsIdrequests, @RequestBody Suppliers suppliers) {
		suppliersHasRequestsService.saveSuppliersHasRequestsSuppliers(suppliershasrequests_suppliersIdsuppliers, suppliershasrequests_requestsIdrequests, suppliers);
		return suppliersDAO.findSuppliersByPrimaryKey(suppliers.getIdsuppliers());
	}

	/**
	 * Register custom, context-specific property editors
	 * 
	 */
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	 * Delete an existing Requests entity
	 * 
	 */
	@RequestMapping(value = "/SuppliersHasRequests/{suppliershasrequests_suppliersIdsuppliers}/{suppliershasrequests_requestsIdrequests}/requests/{requests_idrequests}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteSuppliersHasRequestsRequests(@PathVariable Integer suppliershasrequests_suppliersIdsuppliers, @PathVariable Integer suppliershasrequests_requestsIdrequests, @PathVariable Integer related_requests_idrequests) {
		suppliersHasRequestsService.deleteSuppliersHasRequestsRequests(suppliershasrequests_suppliersIdsuppliers, suppliershasrequests_requestsIdrequests, related_requests_idrequests);
	}

	/**
	 * View an existing Requests entity
	 * 
	 */
	@RequestMapping(value = "/SuppliersHasRequests/{suppliershasrequests_suppliersIdsuppliers}/{suppliershasrequests_requestsIdrequests}/requests/{requests_idrequests}", method = RequestMethod.GET)
	@ResponseBody
	public Requests loadSuppliersHasRequestsRequests(@PathVariable Integer suppliershasrequests_suppliersIdsuppliers, @PathVariable Integer suppliershasrequests_requestsIdrequests, @PathVariable Integer related_requests_idrequests) {
		Requests requests = requestsDAO.findRequestsByPrimaryKey(related_requests_idrequests, -1, -1);

		return requests;
	}

	/**
	 * Select an existing SuppliersHasRequests entity
	 * 
	 */
	@RequestMapping(value = "/SuppliersHasRequests/{suppliershasrequests_suppliersIdsuppliers}/{suppliershasrequests_requestsIdrequests}", method = RequestMethod.GET)
	@ResponseBody
	public SuppliersHasRequests loadSuppliersHasRequests(@PathVariable Integer suppliershasrequests_suppliersIdsuppliers, @PathVariable Integer suppliershasrequests_requestsIdrequests) {
		return suppliersHasRequestsDAO.findSuppliersHasRequestsByPrimaryKey(suppliershasrequests_suppliersIdsuppliers, suppliershasrequests_requestsIdrequests);
	}

	/**
	 * Save an existing Suppliers entity
	 * 
	 */
	@RequestMapping(value = "/SuppliersHasRequests/{suppliershasrequests_suppliersIdsuppliers}/{suppliershasrequests_requestsIdrequests}/suppliers", method = RequestMethod.PUT)
	@ResponseBody
	public Suppliers saveSuppliersHasRequestsSuppliers(@PathVariable Integer suppliershasrequests_suppliersIdsuppliers, @PathVariable Integer suppliershasrequests_requestsIdrequests, @RequestBody Suppliers suppliers) {
		suppliersHasRequestsService.saveSuppliersHasRequestsSuppliers(suppliershasrequests_suppliersIdsuppliers, suppliershasrequests_requestsIdrequests, suppliers);
		return suppliersDAO.findSuppliersByPrimaryKey(suppliers.getIdsuppliers());
	}

	/**
	 * Get Suppliers entity by SuppliersHasRequests
	 * 
	 */
	@RequestMapping(value = "/SuppliersHasRequests/{suppliershasrequests_suppliersIdsuppliers}/{suppliershasrequests_requestsIdrequests}/suppliers", method = RequestMethod.GET)
	@ResponseBody
	public Suppliers getSuppliersHasRequestsSuppliers(@PathVariable Integer suppliershasrequests_suppliersIdsuppliers, @PathVariable Integer suppliershasrequests_requestsIdrequests) {
		return suppliersHasRequestsDAO.findSuppliersHasRequestsByPrimaryKey(suppliershasrequests_suppliersIdsuppliers, suppliershasrequests_requestsIdrequests).getSuppliers();
	}
}